home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacGofer 0.22d / MacGofer Sources / mac_scrap.c < prev    next >
Encoding:
Text File  |  1994-01-06  |  2.8 KB  |  80 lines  |  [TEXT/MPS ]

  1.  scrapTextLength = 0;
  2.  
  3. loadscrap()
  4. {
  5.   static short lastscrapcount = 0;
  6.   short newscrapcount;
  7.  
  8.   TEHandle scrapTE;
  9.   Handle scrapText;
  10.   
  11.   static Boolean scrapError = FALSE;
  12.  
  13.   long dummyOffset = 0;
  14.  
  15.   /* See if the scrap has changed */
  16.   newscrapcount = InfoScrap()->scrapCount;
  17.   if (newscrapcount == lastscrapcount)
  18.     return;
  19.  
  20.   /* If so, remember the scrapCount and get a handle to its text */
  21.   lastscrapcount = newscrapcount;
  22.   scrapTE = TEHANDLE(scrap);
  23.   scrapText = NewHandle(0);
  24.   scrapTextLength = GetScrap(scrapText,'TEXT',&dummyOffset);
  25.   
  26.   if(scrapTextLength > 32767)
  27.     {
  28.       /* Don't give more than one error for the same scrap overflow */
  29.       if(!scrapError)
  30.         {
  31.           Error("","Clipboard contents too large for Gofer to handle");
  32.           scrapError = TRUE;
  33.     }
  34.     }
  35.   else
  36.     {
  37.       scrapError = FALSE;
  38.       /* Now plug the handle into the scrap's TE record and notify TE */
  39.       DisposeHandle((**scrapTE).hText);
  40.       (**scrapTE).hText = scrapText;
  41.       TECalText(scrapTE);
  42.     
  43.       AdjustScrollBars(scrap);
  44.       AdjustText(scrap);
  45.   
  46.       if(scrapVisible)
  47.         {
  48.           /* The window must be the current port for invalidation */
  49.           GrafPtr saveport;
  50.  
  51.           /* Invalidate the visible region here */
  52.           GetPort(&saveport);
  53.           SetPort(WINDOW(scrap));
  54.  
  55.           EraseRgn(WINDOW(scrap)->visRgn);
  56.           InvalRgn(WINDOW(scrap)->visRgn);
  57.  
  58.           SetPort(saveport);
  59.         }
  60.     }
  61. }
  62.  
  63.  
  64. doscrap()
  65. {
  66.   if(copyscrap)
  67.     {
  68.       long err;
  69.       if((err=ZeroScrap()) != noErr)
  70.         AbortErrorN("Unexpected result (%d) from ZeroScrap",err);
  71.       if((err=TEToScrap()) != noErr)
  72.         AbortErrorN("Unexpected result (%d) from TEToScrap",err);
  73.       else
  74.         {
  75.           loadscrap();
  76.           copyscrap = FALSE;
  77.     }
  78.     }
  79. }
  80.